package com.kingyea.mobilepolice.usermenu.controller;

import com.kingyea.mobilepolice.usermenu.bean.UserMenu;
import com.kingyea.mobilepolice.usermenu.bean.UserMenuPo;
import com.kingyea.mobilepolice.usermenu.service.UserMenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hx
 * @version v1.0.0
 * @description UserMenu 控制层
 * @date Created in 2018-04-17 15:15:37
 */
@RequestMapping(value = "/userMenu")
@RestController
public class UserMenuController {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserMenuController.class);

    @Autowired
    private UserMenuService userMenuService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<UserMenu> list() throws Exception {
        return userMenuService.search(null);
    }

    /**
     * 通过ID查找对象
     *
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public UserMenu detail() throws Exception {
        return userMenuService.getById();
    }

    /**
     * 添加菜单给用户
     *
     * @param po
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/addMenuForUser")
    public Object addMenuForUser(@RequestBody UserMenuPo po) throws Exception {
        return userMenuService.addMenuForUser(po);
    }

    /**
     * 创建
     *
     * @param userMenu
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public UserMenu create(@RequestBody UserMenu userMenu) throws Exception {
        return userMenuService.save(userMenu);
    }

    /**
     * 更新
     *
     * @param userMenu
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public UserMenu update(@RequestBody UserMenu userMenu) throws Exception {
        return userMenuService.update(userMenu);
    }

    /**
     * 删除
     *
     * @return
     */
    @RequestMapping(value = "del/{userId}", method = RequestMethod.DELETE)
    public int delete(@PathVariable("userId") String userId) throws Exception {
        return userMenuService.deleteById(userId);
    }

}
